proc class {args} {
	global stack_ends
	global stack_superclass
	global NAMESPACE
	global SUPERCLASS
	global classes
	
	set access [lindex $args 0]
	set name [lindex $args 1]
	set base {}
	if {[llength $args]==3} {set base [lindex $args 2]}
	
	lappend classes(names) $name
	set classes($name,namespace) $NAMESPACE
	set classes($name,superclass) $SUPERCLASS
	foreach {item} $access {lappend classes($name,access) $item}
	if {[llength $base]>0} {
		set classes($name,base) [lindex $base 0]
		set classes($name,interfaces) ""
		foreach {item} [lrange $base 1 [expr {[llength $base]-1}]] {
			lappend classes($name,interfaces) $item
		}
	} {
		set classes($name,base) ""
		set classes($name,interfaces) ""
	}

	push stack_ends [info body end]
	push stack_superclass $SUPERCLASS
	if {$SUPERCLASS!=""} {
		set SUPERCLASS $SUPERCLASS.$name
	} {
		set SUPERCLASS $name
	}
	proc end {} [info body class_end]
}

proc class_end {} {
	global stack_ends
	global stack_superclass
	global SUPERCLASS

	set SUPERCLASS [pop $stack_superclass]
	proc end {} [pop $stack_ends]
}